package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.BuyFirstUser;
import com.sc.nft.entity.RushBuyUser;
import com.sc.nft.entity.vo.BuyFirstUserListVO;
import com.sc.nft.entity.vo.RushBuyUserListVO;
import com.sc.nft.mapper.RushBuyUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * (sc_rush_buy_user)数据DAO
 *
 * @author Sun
 * @since 2022-08-19 11:31:30
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class RushBuyUserDao extends ServiceImpl<RushBuyUserMapper, RushBuyUser> {

    public RushBuyUser selectByProductIdAndUserId(Long productId, Long userId) {
        LambdaQueryWrapper<RushBuyUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RushBuyUser::getProductId,productId);
        wrapper.eq(RushBuyUser::getUserBuyFirstId,userId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Page<RushBuyUserListVO> rushBuyUserList(Long productId, String userTel, int pageNo, int pageSize) {
        return baseMapper.rushBuyUserList(productId,userTel,new Page(pageNo,pageSize));
    }

    public Boolean getIsExistByProductId(Long productId) {
        LambdaQueryWrapper<RushBuyUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RushBuyUser::getProductId, productId);
        return count(wrapper) > 0;
    }
}